import 'dart:ui';
import 'package:chinese_font_library/chinese_font_library.dart';
import 'package:deepseek_client/common/utils/SpUtils.dart';
import 'package:deepseek_client/page/MainPage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'common/db/AppDatabase.dart';
import 'common/db/DbManager.dart';
import 'common/network/DioUtils.dart';

void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await dotenv.load(fileName: "api_key.env");
  SpUtils.getInstance().init();
  init();
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    statusBarColor: Colors.white,
    statusBarBrightness: Brightness.dark,
    statusBarIconBrightness: Brightness.dark,
  ));
  runApp(const DeepSeekApp());
}

Future<void> init() async{
  database = await $FloorAppDatabase.databaseBuilder('deepseek_application.db').build();
  await DynamicFont.asset(
    fontFamily: "syst-regular",
    key: 'assets/syst-regular.otf',
  ).load();
  await DynamicFont.asset(
    fontFamily: "ks",
    key: 'assets/ks.ttf',
  ).load();
  await DynamicFont.asset(
    fontFamily: "微软正黑",
    key: 'assets/MicrosoftZhengHei.ttf',
  ).load();


}

class DeepSeekApp extends StatelessWidget {
  const DeepSeekApp({super.key});

  @override
  Widget build(BuildContext context) {
    final textTheme = Theme.of(context).textTheme;
    return ScreenUtilInit(
      designSize: const Size(1080, 720),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context , child) {
        return MaterialApp(
          title: '炎龙',
          scrollBehavior: const MaterialScrollBehavior().copyWith(
            physics: const BouncingScrollPhysics(
                decelerationRate: ScrollDecelerationRate.normal),
            dragDevices: {
              PointerDeviceKind.touch, // 触摸设备
              PointerDeviceKind.mouse, // 鼠标设备
              PointerDeviceKind.stylus,
              PointerDeviceKind.invertedStylus,
              PointerDeviceKind.trackpad
            },
          ),
          theme: ThemeData(
              colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
              useMaterial3: false,
              textTheme: textTheme.apply(fontFamily: "微软正黑")
          ),
          debugShowCheckedModeBanner: false,
          home: MainPage(),
        );
      },
    );
  }
}

